<!--------------------------------------------------------------
>//	Company:	HTHK
>//	NAME:	    StaffExport.jsp
>//	TITLE:	    Monthly Staff Report by Project
>//	FUNCTION:	Monthly Staff Report
>//	BY:	        Beyes Xia
>//	DATE:	    17/12/2003
<!--	update_date	14-01-2004
<!--	update_by	Poly Li
>// --------------------------------------------------------------
-->

<%@ include file="../tssheader.jsp" %>
<%@ page import="tss.options.*" %>

<SCRIPT Language="Javascript" SRC="<%=contextPath%>/tss/staffabsencereport/Calendar1-821.js"></script>
<%
    try{
//	YearOptions yearFrom = new YearOptions();
//	MonthOptions monthFrom = new MonthOptions();
//    	YearOptions yearTo = new YearOptions();
//	MonthOptions monthTo = new MonthOptions();

	ProjectOptions projectOptions = new ProjectOptions();
	StaffOptions staffOptions=new StaffOptions();

        String projectName =session.getAttribute("project_name")==null?"":(String)session.getAttribute("project_name");
        String staffName = session.getAttribute("staff_name")==null?"":(String)session.getAttribute("staff_name");

//	String year_from = session.getAttribute("yearFrom")==null?"":(String)session.getAttribute("yearFrom");
//	String month_from = session.getAttribute("monthFrom")==null?"":(String)session.getAttribute("monthFrom");
//	String year_to = session.getAttribute("yearTo")==null?"":(String)session.getAttribute("yearTo");
//	String month_to = session.getAttribute("monthTo")==null?"":(String)session.getAttribute("monthTo");

      String dateFrom = session.getAttribute("date_from")==null?"":(String)session.getAttribute("date_from");
      String dateTo = session.getAttribute("date_to")==null?"":(String)session.getAttribute("date_to");
%>
<script language="JavaScript1.1">

/**
	function formValidation()
	{
        var d1 = fm.year_from.value;
	var d2 = fm.month_from.value;
	var d3 = fm.year_to.value;
	var d4 = fm.month_to.value;
        if (d1.length==0 || d2.length==0 || d3.length==0 || d2.length==0)
		{
			alert("Year and Month should be related!");
			return false;
		}

        if (d1>d3 || (d1==d3 && d2>d4))
		{
			alert("Date From must be earlier then Date To!");
			return false;
		}
		return true;
        }
**/
function formValidation()
{
    if (!checkDate(fm.selected_date))
	{
		return false;
	}
    if (!checkDate1(fm.selected_date1))
	{
		return false;
	}
    if (!checkFromTO())
       {
            return false;
       }
       return true;

	
}

function tss_calendar()
{
   var today = new Date();
   show_calendar('fm.selected_date', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function tss_calendar1()
{
   var today = new Date();
   show_calendar('fm.selected_date1', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function init()
{
   var today = new Date();
   //var today1 = new Date();
   month=(today.getMonth()+1>9)?(today.getMonth()+1):"0"+(today.getMonth()+1);
   date=(today.getDate()>9)?today.getDate():("0"+today.getDate());
   month1=(today.getMonth()+1>9)?(today.getMonth()+1):"0"+(today.getMonth()+1);
   date1=(today.getDate()>9)?today.getDate():("0"+today.getDate());
   fm.selected_date.value=today.getYear()+"-"+month+"-"+date;
   fm.selected_date1.value=today.getYear()+"-"+month1+"-"+date1;
}
 function checkDate(object) {
    var obj=object;
    var d = obj.value;
    if (obj.value==null||obj.value.length==0)
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}
    if (obj.value!=null && obj.value.length!=10)
	{
       alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
//    if (chLen(obj," date field (YYYY-MM-DD) ",10)==false)
//       return false;
    if (d.substring(4,5)!="-" || d.substring(7,8)!="-") {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    var day = d.substring(8,10);
    var month = d.substring(5,7);
    var year = d.substring(0,4);
    if (day==null || isNaN(day)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (month==null || isNaN(month)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (day==null || isNaN(day)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (day < 1 || day > 31) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if (month < 1 || month > 12) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if (month == 2) {
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
        }
    }
    return true;
 }

   //Added by Mike. 2004/1/13.
  function checkDate1(object1) {
    var obj1=object1;
    var d1 = obj1.value;
    if (obj1.value==null||obj1.value.length==0)
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}
    if (obj1.value!=null && obj1.value.length!=10)
	{
       alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
//    if (chLen(obj1," date field (YYYY-MM-DD) ",10)==false)
//       return false;
    if (d1.substring(4,5)!="-" || d1.substring(7,8)!="-") {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    var day1 = d1.substring(8,10);
    var month1 = d1.substring(5,7);
    var year1 = d1.substring(0,4);
    if (day1==null || isNaN(day1)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (month1==null || isNaN(month1)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (day1==null || isNaN(day1)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }
    if (day1 < 1 || day1 > 31) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if (month1 < 1 || month1 > 12) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if ((month1==4 || month1==6 || month1==9 || month1==11) && day1==31) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
    }

    if (month1 == 2) {
        var isleap1 = (year1 % 4 == 0 && (year1 % 100 != 0 || year1 % 400 == 0));
        if (day1 > 29 || (day1==29 && !isleap1)) {
		alert("Please input correct date with format as YYYY-MM-DD.");
       return false;
        }
    }
    return true;
 }
function checkFromTO()
{
	if(fm.selected_date.value.length!=0 && fm.selected_date1.value.length!=0 && fm.selected_date.value>fm.selected_date1.value)
	{
		alert("Date From must be earlier than Date To");
		return false;
	}
        return true;

}
function mysubmit()
{
            if (!formValidation())
			{
                return "tss/staffreport/StaffReport.jsp";
			}
            fm.submit();
}
function myReset()
{
 	fm.staff_name.options[0].selected = true;
	fm.project_name.options[0].selected = true;
	fm.selected_date.value = "";
	fm.selected_date1.value = "";
}
</script>
<body>
<h2>Monthly Staff Report by Project</h2>
<form id=fm method=post action='<%=contextPath%>/servlet/tss.staffreport.StaffReportSearch' >
<table cols=5 >


<tr>
  <td>Project Name:</td>
  <td>
	  <select name='project_name'>
		<%=projectOptions.getOptions(projectName,false)%>
	  </select>
  </td>
  <td>&nbsp;</td>
</tr>

<tr>
  <td>Staff No:</td>
  <td>
          <select name='staff_name'>
                  <%=staffOptions.getOptions(staffName,false)%>
          </select>
  </td>
  <td>&nbsp;</td>
</tr>
<!--Modified by Mike. 2004-01-13. -->
<tr>
        <td width='20%'><b>Date Range:</b></td>
        <td >From :&nbsp;
        <input type=text name='selected_date' maxlength=10  ALIGN='LEFT' value='<%=dateFrom%>'>
        <input type=button name=but_cal onClick="tss_calendar();" value='...'>(YYYY-MM-DD)*</td>
</tr>
<tr>
        <br>
        <td>&nbsp;&nbsp;</td>
        <td >To :&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;<input type=text name='selected_date1' maxlength=10  ALIGN='LEFT' value='<%=dateTo%>'>
        <input type=button name=but_cal1 onClick="tss_calendar1();" value='...'>(YYYY-MM-DD)*</td>
</tr>
<!--End modified SQL by Mike. 2004-01-13. -->

</table>
<br>
<hr>
<p>
  <INPUT type=button value='Export' onclick="mysubmit()" >
  <INPUT type=button value='Cancel' onclick="myReset()">
</p>
</form>
<%  }catch(Exception e) {
	out.println(e.toString());
}%>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>
